export function swap(arr: number[], i: number, j: number) {
  const temp = arr[i];
  arr[i] = arr[j];
  arr[j] = temp;
}

export function isSorted(arr: number[]): boolean {
  for (let i = 0; i < arr.length - 1; i++) {
    if (arr[i] > arr[i + 1]) return false;
  }
  return true;
}

type SortAlgoFn = (arr: number[]) => number[];

export function testSort(sortFn: SortAlgoFn) {
  //随即一个长度为10的数组
  const number = Array.from({ length: 10 }, () => {
    return Math.floor(Math.random() * 500);
  });

  console.log(`排序前数组`, number);
  const newArr = sortFn(number);
  console.log(`排序后数组`, newArr);

  console.log(`排序是否正确：${isSorted(newArr)}`);
}
